package com.yuesystem.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuesystem.entity.Question;
import com.yuesystem.mapper.QuestionMapper;
import com.yuesystem.service.QuestionService;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



/**
 * 问题实现类.
 */
@Service
@Slf4j
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question>
    implements QuestionService {
  @Autowired
  private QuestionMapper questionMapper;
  
  @Override
  public List<Question> getQuestion() {
    QueryWrapper<Question> wrapper = new QueryWrapper();
    wrapper.orderByDesc("num");
    List<Question> questions = questionMapper.selectList(wrapper);
    List<Question> list = questions.subList(0, 5);
    return list;
  }
  
  @Override
  public Question getAnswer(Long id) {
    Question question = questionMapper.selectById(id);
    question.setNum(question.getNum() + 1);
    this.updateById(question);
    return question;
  }
}
